{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "176a0c9f",
   "metadata": {},
   "source": [
    "---\n",
    "* 2023-10-1\n",
    "* 课程：Python语言\n",
    "* week04（上课周）\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f633747",
   "metadata": {},
   "source": [
    "# 1.本周内容\n",
    "## 1.数值\n",
    "## 2.字符串\n",
    "## 3.range()函数\n",
    "## 4.for循环\n",
    "# 2.数值\n",
    "> 1. 数值的概念---python教程\n",
    "> 2. 数值的总结---python参考\n",
    "> 3. 数值的分类（type）\n",
    ">> 1. int\n",
    ">> 2. float\n",
    ">> 3. complex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "26dc1b16",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2+2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0ee6e09a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "50-5*6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5a685330",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.6"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "8/5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "8e2d5f42",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17//3 # 取整"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d5a79a77",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17%3 # 取余"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "878d714f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5**2 # **平方"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "83b46e90",
   "metadata": {},
   "outputs": [],
   "source": [
    "width=25\n",
    "height=50"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "49d80f0a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1250"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "width*height"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "f7f40851",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数值的方法\n",
    "abs(-8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "bd3c2f18",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数值类型\n",
    "a = 2023"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "dcd77559",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "ec742c73",
   "metadata": {},
   "outputs": [],
   "source": [
    "PI=3.1415926"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "f5275d60",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "float"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(PI)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "59df39e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "b=3+2j"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "7f44a57f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "complex"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26e59da2",
   "metadata": {},
   "source": [
    "# 3.字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f62a98cd",
   "metadata": {},
   "source": [
    "> 1. 字符串的概念与形态\n",
    "> 2. 字符串的一般方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "99164a42",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'spam eggs'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'spam eggs'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "a3b556fc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Paris rabbit got your back :)Yay!'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Paris rabbit got your back :)Yay!\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7c7043ee",
   "metadata": {},
   "source": [
    "* 笔记：如果引号里面是数值，其结果仍未字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "41f0e114",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1975'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'1975'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "e03f4e0f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type('1975')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "466e5110",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "unterminated string literal (detected at line 1) (3578565646.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Cell \u001b[1;32mIn[21], line 1\u001b[1;36m\u001b[0m\n\u001b[1;33m    'doesn't'\u001b[0m\n\u001b[1;37m            ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unterminated string literal (detected at line 1)\n"
     ]
    }
   ],
   "source": [
    "'doesn't'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "1b0e3832",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "7c6947c4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串的重要特征： 序列\n",
    "\n",
    "地址 =\"广州南方学院温泉大道882号广州南方学院\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "0578ade6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院温泉大道882号广州南方学院'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "6aa3a10b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 序列实践\n",
    "# 序列：自然数顺序从左到右依次排序\n",
    "地址[0] #取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "2d58e1a6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'南方学'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[2:5] #切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "b1732f8e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'学院'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 请用复数取出\"学院\"\n",
    "地址[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "2f8c0db7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址.count(\"广州\") #出现的次数（查询数量）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "d1236f99",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'温泉大道'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 通过上面的方法尝试输出\"温泉大道\"\n",
    "地址[6:10]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4cd16fe6",
   "metadata": {},
   "source": [
    "# 4. for循环和range()方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "daf78d82",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广,\n",
      "州,\n",
      "南,\n",
      "方,\n",
      "学,\n",
      "院,\n",
      "温,\n",
      "泉,\n",
      "大,\n",
      "道,\n",
      "8,\n",
      "8,\n",
      "2,\n",
      "号,\n",
      "广,\n",
      "州,\n",
      "南,\n",
      "方,\n",
      "学,\n",
      "院,\n"
     ]
    }
   ],
   "source": [
    "# 把如下操作成为：循环遍历\n",
    "for item in 地址:\n",
    "    print(item+\",\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9ac29646",
   "metadata": {},
   "source": [
    "* 笔记 : range()可以确定范围，并决定for循环的次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "336f5780",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n",
      "18\n",
      "19\n"
     ]
    }
   ],
   "source": [
    "for i in range(20):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "36b40b5a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n",
      "hello!\n"
     ]
    }
   ],
   "source": [
    "for i in range(20):\n",
    "    print(\"hello!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "d9d18f79",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n",
      "18\n",
      "19\n"
     ]
    }
   ],
   "source": [
    "for i in range(10,20):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2df1b90c",
   "metadata": {},
   "source": [
    "# for循环实践"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c1200d86",
   "metadata": {},
   "source": [
    "## 实践一:创建学号\n",
    "## 增加条件判断，优化学号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "4bca9a8b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20230103010\n",
      "20230103011\n",
      "20230103012\n",
      "20230103013\n",
      "20230103014\n",
      "20230103015\n",
      "20230103016\n",
      "20230103017\n",
      "20230103018\n",
      "20230103019\n",
      "202301030110\n",
      "202301030111\n",
      "202301030112\n",
      "202301030113\n",
      "202301030114\n",
      "202301030115\n",
      "202301030116\n",
      "202301030117\n",
      "202301030118\n",
      "202301030119\n",
      "202301030120\n",
      "202301030121\n",
      "202301030122\n",
      "202301030123\n",
      "202301030124\n",
      "202301030125\n",
      "202301030126\n",
      "202301030127\n",
      "202301030128\n",
      "202301030129\n",
      "202301030130\n",
      "202301030131\n",
      "202301030132\n",
      "202301030133\n",
      "202301030134\n",
      "202301030135\n",
      "202301030136\n",
      "202301030137\n",
      "202301030138\n",
      "202301030139\n",
      "202301030140\n",
      "202301030141\n",
      "202301030142\n",
      "202301030143\n",
      "202301030144\n",
      "202301030145\n",
      "202301030146\n",
      "202301030147\n",
      "202301030148\n",
      "202301030149\n",
      "202301030150\n",
      "202301030151\n",
      "202301030152\n",
      "202301030153\n",
      "202301030154\n",
      "202301030155\n",
      "202301030156\n",
      "202301030157\n",
      "202301030158\n",
      "202301030159\n",
      "202301030160\n",
      "202301030161\n",
      "202301030162\n",
      "202301030163\n",
      "202301030164\n",
      "202301030165\n",
      "202301030166\n",
      "202301030167\n",
      "202301030168\n",
      "202301030169\n"
     ]
    }
   ],
   "source": [
    "for i in range(70):\n",
    "    print(\"2023010301\"+str(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "acb8ca39",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "202301030110\n",
      "202301030111\n",
      "202301030112\n",
      "202301030113\n",
      "202301030114\n",
      "202301030115\n",
      "202301030116\n",
      "202301030117\n",
      "202301030118\n",
      "202301030119\n",
      "202301030120\n",
      "202301030121\n",
      "202301030122\n",
      "202301030123\n",
      "202301030124\n",
      "202301030125\n",
      "202301030126\n",
      "202301030127\n",
      "202301030128\n",
      "202301030129\n",
      "202301030130\n",
      "202301030131\n",
      "202301030132\n",
      "202301030133\n",
      "202301030134\n",
      "202301030135\n",
      "202301030136\n",
      "202301030137\n",
      "202301030138\n",
      "202301030139\n",
      "202301030140\n",
      "202301030141\n",
      "202301030142\n",
      "202301030143\n",
      "202301030144\n",
      "202301030145\n",
      "202301030146\n",
      "202301030147\n",
      "202301030148\n",
      "202301030149\n",
      "202301030150\n",
      "202301030151\n",
      "202301030152\n",
      "202301030153\n",
      "202301030154\n",
      "202301030155\n",
      "202301030156\n",
      "202301030157\n",
      "202301030158\n",
      "202301030159\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,60):\n",
    "#   print(i)\n",
    "    if i >9:\n",
    "         print(\"2023010301\" +str(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "5457f1c5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "202301030101\n",
      "202301030102\n",
      "202301030103\n",
      "202301030104\n",
      "202301030105\n",
      "202301030106\n",
      "202301030107\n",
      "202301030108\n",
      "202301030109\n",
      "202301030110\n",
      "202301030111\n",
      "202301030112\n",
      "202301030113\n",
      "202301030114\n",
      "202301030115\n",
      "202301030116\n",
      "202301030117\n",
      "202301030118\n",
      "202301030119\n",
      "202301030120\n",
      "202301030121\n",
      "202301030122\n",
      "202301030123\n",
      "202301030124\n",
      "202301030125\n",
      "202301030126\n",
      "202301030127\n",
      "202301030128\n",
      "202301030129\n",
      "202301030130\n",
      "202301030131\n",
      "202301030132\n",
      "202301030133\n",
      "202301030134\n",
      "202301030135\n",
      "202301030136\n",
      "202301030137\n",
      "202301030138\n",
      "202301030139\n",
      "202301030140\n",
      "202301030141\n",
      "202301030142\n",
      "202301030143\n",
      "202301030144\n",
      "202301030145\n",
      "202301030146\n",
      "202301030147\n",
      "202301030148\n",
      "202301030149\n",
      "202301030150\n",
      "202301030151\n",
      "202301030152\n",
      "202301030153\n",
      "202301030154\n",
      "202301030155\n",
      "202301030156\n",
      "202301030157\n",
      "202301030158\n",
      "202301030159\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,60):\n",
    "#   print(i)\n",
    "    if i >9:\n",
    "         print(\"2023010301\" +str(i))\n",
    "    else:\n",
    "        print(\"20230103010\"+str(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6c6c65c0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
